package com.lex.newbasketball.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lex.newbasketball.R;
import com.lex.newbasketball.entity.DiscoveryEntity;
import com.lex.newbasketball.entity.WonderEntity;

import java.util.List;

public class DiscoveryAdapter extends BaseAdapter{
    private Context context;
    private List<DiscoveryEntity>discoveryEntityList;

    public DiscoveryAdapter(Context context, List<DiscoveryEntity> discoveryEntityList){
        this.context = context;
        this.discoveryEntityList = discoveryEntityList;
    }

    @Override
    public int getCount() {
        return discoveryEntityList.size();
    }

    @Override
    public Object getItem(int i) {
        return discoveryEntityList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    public class ViewHolder{
        private ImageView discovery, center_img;
        private TextView text;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        DiscoveryEntity discoveryEntity = discoveryEntityList.get(i);
        ViewHolder viewHolder = null;
        if (viewHolder == null){
            convertView = convertView.inflate(context, R.layout.item_discovery_item, null);
            viewHolder = new ViewHolder();
            viewHolder.discovery = (ImageView) convertView.findViewById(R.id.image_discovery);
            viewHolder.center_img = (ImageView) convertView.findViewById(R.id.center_image_discovery);
            viewHolder.text = (TextView) convertView.findViewById(R.id.text_discovery);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.discovery.setImageResource(discoveryEntity.getDiscovery());
        viewHolder.center_img.setImageResource(discoveryEntity.getCenter_img());
        viewHolder.text.setText(discoveryEntity.getText());
        return convertView;
    }
}
